﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using Newtonsoft.Json;
using System.Data.Entity.Infrastructure;
using _24_Hour_Blogger.Models;
using _24_Hour_Blogger.Models.Content;
using _24_Hour_Blogger.Library;

namespace _24_Hour_Blogger.ViewModels.Content
{
    public partial class ArticleMediaViewModel : ViewModelBase<ArticleMedia>
    {

        public ArticleMediaViewModel()
        {
            this.Entity = new ArticleMedia();
        }

        DbContext dataContext = null;
        DbSet<ArticleMedia> entitiesCollection = null;
        ArticleMedia entityClass = null;
        public ArticleMediaViewModel(DbContext dataContext, DbSet<ArticleMedia> entitiesCollection, ArticleMedia entityClass)
        {
            this.dataContext = dataContext;
            this.entitiesCollection = entitiesCollection;
            this.entityClass = entityClass;
            if (this.entityClass == null)
            {
                this.entityClass = new ArticleMedia();
            }
            this.Entity = this.entityClass;
        }

        public override Int32 Id
        {
            get
            {
                return Entity.ArticleMediaId;
            }
            set
            {

                Entity.ArticleMediaId = value;
            }
        }

        public Int32 ArticleMediaId
        {
            get
            {
                return Entity.ArticleMediaId;
            }
            set
            {
                if (value > 0)

                    if (Entity.ArticleMediaId != value)
                    {
                        Entity.ArticleMediaId = value;
                        this.IsDirty = true;
                    }
            }
        }

        public int ArticleId
        {
            get
            {
                return Entity.ArticleId;
            }
            set
            {
                if (Entity.ArticleId != value)
                {
                    Entity.ArticleId = value;
                    this.IsDirty = true;
                }
            }
        }

        public override DateTime CreatedDate
        {
            get
            {
                return Entity.CreatedDate;
            }
            set
            {
                if (Entity.CreatedDate != value)
                {
                    Entity.CreatedDate = value;
                    this.IsDirty = true;
                }
            }
        }

        public override DateTime UpdatedDate
        {
            get
            {
                return Entity.UpdatedDate;
            }
            set
            {
                if (Entity.UpdatedDate != value)
                {
                    Entity.UpdatedDate = value;
                    this.IsDirty = true;
                }
            }
        }

        public override Int32 CreatedByUserId
        {
            get
            {
                return Entity.CreatedByUserId;
            }
            set
            {
                if (Entity.CreatedByUserId != value)
                {
                    Entity.CreatedByUserId = value;
                    this.IsDirty = true;
                }
            }
        }

        public override Int32 UpdatedByUserId
        {
            get
            {
                return Entity.UpdatedByUserId;
            }
            set
            {
                if (Entity.UpdatedByUserId != value)
                {
                    Entity.UpdatedByUserId = value;
                    this.IsDirty = true;
                }
            }
        }


        private ArticleViewModel _Article;
        [JsonIgnore]
        public ArticleViewModel Article
        {
            get
            {

                if (_Article == null)
                {
                    if (this.Entity != null && this.Entity.Article != null)
                        _Article = new ArticleViewModel(dataContext, DataStore.ContentEntities.Articles, this.Entity.Article);
                    else
                        if (dataContext == null)
                        {}   //    _Article = new ArticleViewModel();
                        else
                            _Article = new ArticleViewModel(dataContext, DataStore.ContentEntities.Articles, null);
                }

                return _Article;
            }
            set
            {
                if (this.dataContext != null)
                    if (this.Entity.Article != value.Entity)
                    {
                        this.Entity.Article = value.Entity;
                    }
                if (_Article != value)
                {
                    _Article = value;
                }
            }
        }
    }
}